package com.common.android.utils.httpRequest;

import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.message.BasicHeader;

import com.product.android.business.config.Configuration;

import android.content.Context;
import android.text.TextUtils;

/**
 * http 通讯
 * 
 * @author yyy
 * 
 */
public class OapHttpRequest extends HttpRequest {
    private static OapHttpRequest mHttp;

    public static OapHttpRequest getInstance(Context ctx) {
        if (mHttp == null)
            mHttp = new OapHttpRequest(ctx);
        return mHttp;
    }

    protected OapHttpRequest(Context ctx) {
        super(ctx);
        TAG = "OapHttpRequest";
    }
    
    private String oap_id;

	public void setOapId(String oap_id) {
		this.oap_id = oap_id;
	}
	
	/**
	 * 设置头部代理。
	 */
	private ISetHeadAgent agent;
	
	/**
	 * 设置头部请求代理。
	 * <br>Created 2014-5-20 上午11:42:30
	 * @param agent_ob 代理句柄
	 * @author       suchangjun
	*/
	@Override
	public void setAgent(ISetHeadAgent agent_ob) {
		this.agent = agent_ob;
	}
	
    
    @Override
	public void setHttpHeader(HttpRequestBase request) {
        super.setHttpHeader(request);
        if(!TextUtils.isEmpty(oap_id)){
        	 request.addHeader(new BasicHeader("UID", String.valueOf(oap_id)));
        }
        // 暂时明星APP和校友有要求加这个头部
        if(!TextUtils.isEmpty(Configuration.CLOUNDID)){
        	 request.addHeader(new BasicHeader("CLOUDID", Configuration.CLOUNDID));
        }
        //业务自己设置头部。
        if(agent!=null)
        {
        	agent.setHttpHeader(request);
        }
    }

}
